Add verbose Learning Mode denial logging - #916
Add verbose Learning Mode denial logging#916Richie Gomez (richiemsft) wants to merge 35 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Route wxc-exec --audit through captureDenials so native PSEC/V2 remains preferred and guarded WPR provides compatible analysis and ETL retention. Reuse canonical denials for adjusted policy generation and support retainEtl consistently across both capture providers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Update repository guidance for captureDenials-backed audit routing and guarded retainEtl parity. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
a300213 to
5e1090c
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
Emit a bounded, username-redacted Data Loop JSON sibling containing canonical denial occurrences and classified decoder outcomes. Keep paired output transactional across native, guarded, and audit capture paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4eff3ee2-323c-494d-99b9-f7b54e495216
dbf31fe to
abf1219
Compare
There was a problem hiding this comment.
Pull request overview
Adds bounded, redacted Data Loop diagnostics alongside Learning Mode denial output and integrates them across native capture, guarded WPR, and audit workflows.
Changes:
- Adds the Data Loop model, aggregation, sanitization, and paired output.
- Adds process-scoped guarded-WPR ETL relogging and retention.
- Reworks
--auditto consumecaptureDenialsartifacts directly.
Reviewed changes
Copilot reviewed 29 out of 30 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
.github/copilot-instructions.md |
Updates Learning Mode architecture guidance. |
README.md |
Revises audit-mode documentation. |
docs/learning-mode/capabilities.md |
Documents Data Loop and retained ETL behavior. |
src/Cargo.lock |
Records the new dependency edge. |
src/backends/appcontainer/common/src/appcontainer_runner.rs |
Supports guarded ETL transfer. |
src/backends/appcontainer/common/src/base_container_runner.rs |
Integrates retained guarded captures. |
src/backends/appcontainer/common/src/capture_output.rs |
Adds paired denial/Data Loop output. |
src/backends/appcontainer/common/src/guarded_capture.rs |
Extends guarded-capture interfaces. |
src/backends/learning_mode/windows/src/capability_dacl.rs |
Adds diagnostic metadata to recovered denials. |
src/backends/learning_mode/windows/src/etl_decode.rs |
Aggregates Data Loop outcomes and selects relog events. |
src/backends/learning_mode/windows/src/etl_filter.rs |
Adds process-scoped ETL relogging. |
src/backends/learning_mode/windows/src/extractors.rs |
Adds sanitization and diagnostic classification. |
src/backends/learning_mode/windows/src/lib.rs |
Exports ETL filtering. |
src/backends/learning_mode/windows/src/tdh_decode.rs |
Categorizes recoverable decoding failures. |
src/core/learning_mode_core/src/analyze.rs |
Carries and bounds Data Loop results. |
src/core/learning_mode_core/src/data_loop.rs |
Defines the Data Loop model and writer. |
src/core/learning_mode_core/src/lib.rs |
Exports Data Loop APIs. |
src/core/learning_mode_core/src/model.rs |
Makes classifications sortable. |
src/core/mxc_engine/src/guarded_capture.rs |
Implements guarded trace transfer. |
src/core/mxc_engine/src/lib.rs |
Exports audit runner resolution. |
src/core/mxc_engine/src/run.rs |
Adds audit-specific resolver entry point. |
src/core/wxc/Cargo.toml |
Adds Learning Mode core dependency. |
src/core/wxc/src/audit.rs |
Relocates and post-processes capture artifacts. |
src/core/wxc/src/main.rs |
Routes audit through captureDenials. |
src/host/plm/readme.md |
Documents guarded analysis and validation. |
src/host/plm/src/analysis.rs |
Returns canonical documents after writing. |
src/host/plm/src/elevated.rs |
Adds filtered analysis/trace transfer protocol. |
src/host/plm/src/log.rs |
Consumes guardian-returned analysis directly. |
src/host/plm/src/secure_scratch.rs |
Manages filtered ETL scratch storage. |
src/host/plm/src/stop.rs |
Extracts canonical-denial post-processing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Keep excluded namespace evidence uniquely identifiable, retain guarded-trace unknown schemas and brokered capability events, and emit canonical/Data Loop outputs as a transactional pair. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
Use targeted broker PID decoding without aborting on unrelated malformed payloads, and make rollback ownership-aware, portable, and no-clobber. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
Preserve malformed scoped capability events, retain uncached TDH schemas after the cache cap, and make rollback recovery no-clobber and deletion tolerant. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
Detect in-place overwrites before deleting a promoted output and directly exercise TDH short-circuit and cache-capacity behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
Restore backups even when quarantined output cleanup fails, preserve both errors, and hash promoted files from a known offset. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
Recover the brokered payload ProcessId when full event decoding fails after that property, and drop only events that remain unscopable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
Surface quarantine restoration failures with accurate rollback context and codify malformed capability PID fallback scoping. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
Identify backup, quarantine, and destination paths in cleanup and restoration failures while preserving strict error propagation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: acb632fc-7b75-4d0e-9be5-f11de51652bf
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 33 out of 34 changed files in this pull request and generated no new comments.
Suppressed comments (4)
src/core/learning_mode_core/src/data_loop.rs:184
- Once the signature set contains only canonical groups, every new distinct canonical event calls
evict_one_noncanonical_group, which scans all 4,096 entries before overflowing it. At the 1,000,000-event bound this can perform billions of comparisons, turning an intentionally bounded diagnostic path into a CPU bottleneck. Track whether any noncanonical group exists (or partition/index the two classes) so the full scan is skipped when eviction cannot succeed.
while self.signatures.len() >= MAX_DATA_LOOP_GROUPS
|| retained_bytes.saturating_add(serialized_len) > max_bytes
{
if !signature.reason.is_canonical_denial()
|| !self.evict_one_noncanonical_group(Some(retained_bytes))
{
src/host/plm/src/elevated.rs:2341
- This helper is now also used for guarded
captureDenialsretention, socreate_dir_allmakes a missingoutputPathparent succeed only when guarded WPR plusretainEtlis selected. Native and non-retained captures still fail, and the documented contract says the parent must already exist. Preflight the configured output directory consistently before capture, rather than creating it as a side effect of ETL transfer.
src/core/learning_mode_core/src/paired_output.rs:56 - Every capture creates a unique
.pair.lockfile, butDroponly unlocks it and never removes it. Because capture output names include a per-run ID, these lock files are never reused and accumulate indefinitely in the configured output directory (or the system temp directory for managed outputs). Use an ephemeral/delete-on-close lock strategy, or add race-safe cleanup after the transaction.
impl Drop for OutputPairLock {
fn drop(&mut self) {
let _ = std::fs::File::unlock(&self.file);
}
.github/copilot-instructions.md:216
- This architecture entry still says the output layer writes a single JSON document, but this PR makes
learning_mode_coreown theDataLoopDocumentand paired-output transaction as well. Leaving the repository guidance singular will mislead future changes about the required canonical/Data Loop pair; update this entry to describe both artifacts and their paired emission contract.
- `learning_mode_core` is the **cross-platform learning-mode / captureDenials model + output emitter**: `DeniedResource` (+ `ResourceType`/`AccessType`), `DenialSummary`, the `DenialAnalyzer` decode trait, and `emit` — which writes the on-disk denials deliverable as a **single JSON document** `{ "denials": [...], "summary": {...} }` (`write_document` / `DenialsDocument`) and defines the serializable `DenialsOutputPointer`. It carries no OS-specific code (must not depend on any `backends/*` crate); the Windows ETL decoder implementing `DenialAnalyzer` lives in `backends/learning_mode/windows`. When `processContainer.captureDenials` is set, native PSEC/V2 seals and decodes a managed ETL locally, while guarded WPR relogs its host-wide source into a process-scoped ETL before analysis; both routes write the same canonical JSON through shared output plumbing and return neutral `wxc_common` metadata. Explicit `retainEtl` preserves the native sealed trace or the guarded process-scoped relogged trace after a terminal wait; abandonment discards it. `wxc-exec` serializes the metadata as the one-line stderr pointer at the CLI boundary; Rust/C#/FFI callers receive it programmatically. Each denial's `resource` field holds the file path or the AppContainer capability name; capability denials resolve their capability SID to a friendly name via `backends/learning_mode/windows`'s `capability_names` (well-known `S-1-15-3-…` SID → policy name; custom hashed SIDs fall back to the SID string).
Resolve overlapping Learning Mode audit capture changes while preserving Data Loop denial diagnostics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f9ac49b1-fdfe-4cca-9412-9faa99cef2ab
Darren Hoehna (dhoehna)
left a comment
There was a problem hiding this comment.
Canonical
Does copilot really need to use this every where?
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f9ac49b1-fdfe-4cca-9412-9faa99cef2ab
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
docs/learning-mode/capabilities.md:250
- This file-denial example does not match the emitted schema. For a decoded access-check containing
ObjectName,record_raw_denial_outcomeretains that property (redacted) and deliberately does not synthesizeresource; consumers following this example will look for a field that is absent from normal file signatures. UseObjectNamehere instead.
"properties": [
["PackageSid", "S-1-15-3-1"],
["resource", "<REDACTED>"]
]
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f9ac49b1-fdfe-4cca-9412-9faa99cef2ab
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 25 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/backends/learning_mode/windows/src/extractors.rs:152
- Event 28 is being classified by the presence of both
CategoryandDetail, not by its TDH schema. A UI-shapedLearningModeViolationevent with a malformed/missingDetailtherefore falls through to the capability extractor and is logged ascapability/notActionable(orunresolvedCapability) instead of a UI payload error. This also contradicts the PR's stated rule that malformed event-28 diagnostics use the schema name to choose UI versus capability. Preserve the schema event name inDecodedEventPartsand use it for event-28 routing; property presence can then remain validation within the chosen extractor.
CAPABILITY_DENIAL_EVENT_ID if is_ui_violation_schema(parts) => {
build_denial_from_learning_mode(parts, pid, filetime, provider)
}
CAPABILITY_DENIAL_EVENT_ID => build_denial_from_capability(parts, pid, filetime, provider),
src/backends/learning_mode/windows/src/extractors.rs:649
- Adding
SymbolicLinkasResourceType::Othersends it throughAccumulator::add_raw_denial's existing non-file normalization (etl_decode.rs:254-256). For the covered object name\??\C:,path_norm::to_user_visiblestrips the object-manager prefix and the canonical output becomesC:, even though the documentation promises the raw identifier forotherresources. This loses namespace information and can merge distinct identifiers. Keep object-manager names raw (or restrict user-visible path normalization toResourceType::File) before emitting and deduplicating these new denial types.
let resource_type = match object_type_str {
"File" => ResourceType::File,
"Key" => ResourceType::Other,
"Section" | "SymbolicLink" | "Timer" => ResourceType::Other,
// A present-but-empty object type is a brokered-capability check.
"" => ResourceType::Capability,
_ => return Err(VerboseLoggingExclusionReason::UnsupportedObjectType),
📖 Description
Adds deterministic verbose logging for every successful Learning Mode denial analysis while preserving the canonical policy-output contract and expanding canonical decoding for newly validated ETL shapes.
Each analysis now produces a transactional pair:
denials.jsonretains canonical, actionable denials, including complete file paths.denials.verbose.jsonretains a bounded, deduplicated diagnostic superset. Complete file paths are replaced with<REDACTED>; standalone account names and username components in non-file identifiers are also redacted before bounding or hashing.The verbose logging output includes canonical denial occurrences and closed classifications for outcomes omitted from canonical policy generation, including unusable resource paths, unsupported object types and event schemas, malformed payloads, decoder limits, and unresolved capability events. Stable non-file identifiers such as SIDs, capability names, provider GUIDs, PIDs, and named-object details remain available for diagnosis.
The guarded WPR path now preserves known-provider events through process-scoped selection and replay. Brokered event 28 is scoped using its payload
ProcessId, including partial-decode recovery, rather than the broker's ETW header PID.Native capture and
plm stopshare a transactional paired-output writer. Both JSON files are staged and synchronized before no-clobber promotion, with ownership- and digest-aware rollback. Audit mode consumes these capture artifacts directly and relocates both the JSON pair and retained ETL through no-clobber staging with identity- and digest-verified source cleanup, keeping metadata truthful without deleting files owned by another process.Additional ETL findings
Validation across eight new namespace scenarios (16 retained ETLs: block and allow) identified additional canonical decoder shapes:
CategoryandDetailnow emit canonical UI denials such asresource: "Handles",resourceType: "ui", rather than incorrectly treating the payload's package SID as a capability.Section,SymbolicLink, andTimeraccess checks now emit canonicalotherresources with object-specific access-mask classification.JOB_OBJECT_UILIMIT_HANDLES, primarily cross-process HWND/USER-object handle access.ObjectTypeandObjectName. They remain bounded verbose logging diagnostics because the ETL provides no stable canonical resource identifier.The updated decoder increased canonical coverage in 15 of the 16 supplied ETLs. The remaining ETW Session block trace was an early process-initialization failure and contained none of the newly supported named shapes.
🔗 References
Builds on the Learning Mode capture hardening from #847.
This is for issue #828
🔍 Validation
learning_mode_core: 43 tests passedlearning_mode_windows: 224 tests passedappcontainer_common: 247 tests passedplm: 226 tests passed, 1 ignoredwxc: 40 tests passedlearning_mode_core,learning_mode_windows, andplmwxc-exec.exeandplm.exebuildlm_analyzedecoder run against all 16 supplied retained ETLsui/Handles, Timer, Section, and SymbolicLink output; confirmed event 28 UI no longer emits a bogus package-SID capability✅ Checklist
Cargo.lock, thedependency-feed-checkcheck passes (see docs/pull-requests.md)📋 Issue Type
GitHub Actions runs the PR validation build automatically. The ADO pipeline
(
MXC-PR-Build) is the Azure version of the PR pipeline, kept in parity with the GitHubActions build; it runs on merge to
main, and Microsoft reviewers with write access can trigger iton a PR with
/azp run. See docs/pull-requests.md.If the
dependency-feed-checkcheck fails on a new dependency, the crate must be added tothe feed before the PR can pass. See docs/pull-requests.md
for the steps.
Microsoft Reviewers: Open in CodeFlow